<?php
namespace app\index\controller;
use think\Controller;
use think\Db;
use think\Cookie;

use wxpay\database\WxPayUnifiedOrder;
use wxpay\JsApiPay;
use wxpay\NativePay;
use wxpay\PayNotifyCallBack;
use think\Log;
use wxpay\WxPayApi;
use wxpay\WxPayConfig;

use alipay\wappay\buildermodel\AlipayTradeWapPayContentBuilder;
use alipay\wappay\service\AlipayTradeService;

use pinganpay\Webapp;
use think\Loader;




use pufapay\ConfigUtil;
use pufapay\HttpUtils;
use pufapay\SignUtil;
use pufapay\TDESUtil;

class sign
{
     public static function getSign($secret, $data)
    {

        // 去空
        $data = array_filter($data);

        //签名步骤一：按字典序排序参数
        ksort($data);
        $string_a = http_build_query($data);
        $string_a = urldecode($string_a);

        //签名步骤二：在string后加入mch_key
        $string_sign_temp = $string_a . "&key=" . $secret;

        //签名步骤三：MD5加密
        $sign = md5($string_sign_temp);

        // 签名步骤四：所有字符转为大写
        $result = strtoupper($sign);

        return $result;
    }


    /**
     * @Note   验证签名
     * @param $data
     * @param $orderStatus
     * @return bool
     */
     public static function verifySign($data, $secret) {
        // 验证参数中是否有签名
        if (!isset($data['sign']) || !$data['sign']) {
            return false;
        }
        // 要验证的签名串
        $sign = $data['sign'];
        unset($data['sign']);
        // 生成新的签名、验证传过来的签名
        $sign2 = $this->getSign($secret, $data);

        if ($sign != $sign2) {
            return false;
        }
        return true;
    }


}



class Timer
{

    /**
     * 十三位时间戳
     * @return string
     */
    public static function millisecond()
    {
        list($t1, $t2) = explode(' ', microtime());
        return sprintf('%.0f', (floatval($t1) + floatval($t2)) * 1000);
    }

}
class Encryption
{

    /**
     * 签名
     * @param array $params
     * @param string $secret
     * @return string
     */
    public static function sign($params = [], $secret = '')
    {
        ksort($params);
        $str = '';
        foreach ($params as $k => $v) {
            $str = $str . $k . $v;
        }
        $str = $secret . $str . $secret;
        return strtoupper(md5($str));
    }

}
class Net
{

    /**
     * 原生post请求
     * @param $url //请求链接
     * @param array $params 请求参数
     * @param array $headers 请求头
     * @param $cookieJar cookie文件
     * @return mixed
     */
    public static function post($url, $params=[], $headers=[], $cookieJar='')
    {
        $ch = curl_init();
        curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
        curl_setopt($ch, CURLOPT_HEADER, FALSE);
        curl_setopt($ch, CURLOPT_FOLLOWLOCATION, TRUE);
        curl_setopt($ch, CURLOPT_URL, $url);
        curl_setopt($ch, CURLOPT_REFERER, $url);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
        curl_setopt($ch, CURLOPT_POST, 1);
        curl_setopt($ch, CURLOPT_TIMEOUT, 3);
        curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
        curl_setopt($ch, CURLOPT_POSTFIELDS, $params);
        if ($cookieJar) curl_setopt($ch, CURLOPT_COOKIEJAR, $cookieJar);
        $result = curl_exec($ch);
        curl_close($ch);
        return $result;
      
    }

    /**
     * 原生get请求
     * @param $url //请求链接
     * @param array $headers 请求头
     * @param $cookieJar cookie文件
     * @return mixed
     */
    public static function get($url, $headers=[], $cookieJar='')
    {
        $ch = curl_init();
        curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
        curl_setopt($ch, CURLOPT_HEADER, FALSE);
        curl_setopt($ch, CURLOPT_FOLLOWLOCATION, TRUE);
        curl_setopt($ch, CURLOPT_URL, $url);
        curl_setopt($ch, CURLOPT_REFERER, $url);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
        curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 3);
        curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
        if ($cookieJar) curl_setopt($ch, CURLOPT_COOKIEJAR, $cookieJar);
        $result = curl_exec($ch);
        curl_close($ch);
        return $result;
    }

}

class Pay extends Controller
{

    public function __construct()
    {
        parent::__construct();
    }

    public function yilian_pay($data0)
    {

        $pay_orderid = $data0['balance_sn']; //商户订单号

        $pay_applydate = date("Y-m-d H:i:s");
        $pay_uid = "11665";
        $pay_notifyurl = 'http://'.$_SERVER['HTTP_HOST']."/index/pay/yilian_pay_notify";   //服务端返回地址
        $pay_callbackurl = 'http://'.$_SERVER['HTTP_HOST']."/index/user/index";  //页面跳转返回地址
		$pay_amount = $data0['bpprice'];    //交易金额
        if ($data0['pay_type']=='yilian_bank') {
          $pay_passcode='1011';
        }else {
          $pay_passcode='1010';
        }

		$apikey = 'fu7qoskkttlqgjhf97md7mqaetl7phf9';//商户后台查找

        $signSource = sprintf("pay_uid=%s&pay_orderid=%s&pay_applydate=%s&pay_notifyurl=%s&pay_amount=%s%s", $pay_uid, $pay_orderid, $pay_applydate, $pay_notifyurl,$pay_amount,$apikey);
		$sign = strtoupper(md5($signSource));  //字符串加密处理


      $tjurl = "http://www.57ydzz.cn/User_Huan_index.html";   //网关提交地址

      $jsapi = array(
          "pay_uid"      => $pay_uid,
          "pay_amount"        => $pay_amount,
          "pay_orderid"      => $pay_orderid,
          "pay_passcode"      => $pay_passcode,
          "pay_applydate"    => $pay_applydate,
          "pay_notifyurl"    => $pay_notifyurl,
          "pay_callbackurl"    => $pay_callbackurl,
      );

      $jsapi["pay_md5sign"] = $sign;

        $sHtml = "<form  name='' action='".$tjurl."' method='post' >";
        foreach ($jsapi as $key => $val) {
            $sHtml.= "<input type='hidden' name='".$key."' value='".$val."'/>";
        }
        $sHtml.= "</form>";
        //$sHtml.= "<script>document.forms['youbaopaysubmit'].submit();</script>";


        return $sHtml;

    }
    public function yilian_pay_notify()
    {
		$data = !empty($_POST)?$_POST:$_GET;

      $myfile = fopen("newfile_pay_log.txt", "a+") or die("Unable to open file!");
      fwrite($myfile, "\r\n" . date("Y-m-d H:i:s") . " 信息：" . json_encode($_POST) . " \r\n");
      fclose($myfile);

      //验证签名
      $apikey = "fu7qoskkttlqgjhf97md7mqaetl7phf9";
      $md5_sign = strtoupper(md5("pay_uid=".$data['pay_uid']."&out_trade_id=".$data['out_trade_id']."&orderstatus=".$data['orderstatus']."&paymoney=".$data['paymoney'].$apikey));

      if($data['sign'] == $md5_sign){
            echo 'ok';
            $this->notify_ok_dopay($data['out_trade_id'],$data['paymoney']);
      }

    }

    public function shengbao_pay($data0)
    {
      $pay_memberid = '1920223431';
      $pay_amount  = $data0['bpprice'];    //交易金额
      $pay_applydate = "2018-12-08 13:46:01";  //订单时间
      //$pay_code  = "qgfalipay";   //支付方式

      if ($data0['pay_type']=='shengbao_wx') {
        $pay_code='qgfweixin';
      }else {
        $pay_code='qgfalipay';
      }

      $pay_orderid = $data0['balance_sn'];    //订单号
      $pay_notifyurl = 'http://'.$_SERVER['HTTP_HOST']."/index/pay/shengbao_pay_notify";   //服务端返回地址
      $pay_callbackurl = 'http://'.$_SERVER['HTTP_HOST']."/index/user/index";  //页面跳转返回地址
      $Md5key = '2cef0f19b5d8f52cbfd1dc6ed98161a2';   //密钥
      $tjurl = "http://pay.shengbaovpay.com/pay";   //网关提交地址

      $jsapi = array(
          "merchant"      => $pay_memberid,
          "amount"        => $pay_amount,
          "pay_code"      => $pay_code,
          "order_no"      => $pay_orderid,
          "notify_url"    => $pay_notifyurl,
          "return_url"    => $pay_callbackurl,
          "order_time"    => $pay_applydate,
          "attach"        => '',
          "cuid"          => '',
      );

      require_once(EXTEND_PATH.'shenbao_pay/Md5verify.php');
      $md5Verify = new \Md5Verify();
      $sign = $md5Verify->getSign($jsapi,$Md5key);
      $jsapi["sign"] = $sign;

        $sHtml = "<form  name='' action='".$tjurl."' method='post' >";
        foreach ($jsapi as $key => $val) {
            $sHtml.= "<input type='hidden' name='".$key."' value='".$val."'/>";
        }
        $sHtml.= "</form>";
        //$sHtml.= "<script>document.forms['youbaopaysubmit'].submit();</script>";


        return $sHtml;

    }
    public function shengbao_pay_notify()
    {
      $pay_memberid  = $_POST['merchant'];//商户号
      $pay_amount    =$_POST['amount'];    //用户实际交易金额
      $pay_applydate = $_POST['order_time'];  //订单提交时间
      $sys_order_no  = $_POST['sys_order_no'];   //平台订单号
      $out_order_no   = $_POST['out_order_no']; //商户订单号
      $attach        = '';   //商户上传信息
      $cuid          = '';   //商户上传信息
      $realPrice     = $_POST['realPrice']; //商户订单提交金额
      $sign          = $_POST['sign']; //平台返回签名


      $Md5key        = '2cef0f19b5d8f52cbfd1dc6ed98161a2';   //密钥

      $myfile = fopen("newfile_pay_log.txt", "a+") or die("Unable to open file!");
      fwrite($myfile, "\r\n" . date("Y-m-d H:i:s") . " 信息：" . json_encode($_POST) . " \r\n");
      fclose($myfile);

      $jsapi = array(
          "merchant"      => $pay_memberid,
          "amount"        => $pay_amount,
          "sys_order_no"  => $sys_order_no,
          "out_order_no"  => $out_order_no,
          "order_time"    => $pay_applydate,
          "attach"        => $attach,
          "cuid"          => $cuid,
          "realPrice"     => $realPrice
      );

 	  require_once(EXTEND_PATH.'shenbao_pay/Md5verify.php');
      $md5Verify = new \Md5Verify();
      $local_sign = $md5Verify->getSign($jsapi,$Md5key);
      if($sign == $local_sign){
           echo 'success';
            $this->notify_ok_dopay($out_order_no,$realPrice);
      }

    }

    public function ruibao_pay($data0)
    {
      $pay_memberid = "11138";   //商户ID
      $pay_orderid = $data0['balance_sn'];    //订单号
      $pay_amount = $data0['bpprice'];    //交易金额
      $pay_applydate = date("Y-m-d H:i:s");  //订单时间
      $pay_bankcode = "EBANK";   //银行编码
      $pay_tongdao = "Yalong";   //交易通道
      $pay_tradetype = "";   //通道编码
      $pay_productname="";
      $pay_notifyurl = 'http://'.$_SERVER['HTTP_HOST']."/index/pay/ruibao_pay_notify";//异步回调地址，请保证能正常访问
      $pay_callbackurl = 'http://'.$_SERVER['HTTP_HOST']."/index/user/index";//同步通知地址
      $Md5key = "o0mmsyvefa1b7401f7yml6i8yun83n";    //密钥
      $tjurl = "http://www.yuejipay.com.cn/Pay_Index.html"; //网关提交地址

      $jsapi = array(
          "pay_memberid" => $pay_memberid,
          "pay_orderid" => $pay_orderid,
          "pay_amount" => $pay_amount,
          "pay_applydate" => $pay_applydate,
          "pay_bankcode" => $pay_bankcode,
          "pay_notifyurl" => $pay_notifyurl,
          "pay_callbackurl" => $pay_callbackurl,
      );

      ksort($jsapi);
      $md5str = "";
      foreach ($jsapi as $key => $val) {
          $md5str = $md5str . $key . "=" . $val . "&";
      }
      //echo($md5str . "key=" . $Md5key."<br>");
      $sign = strtoupper(md5($md5str . "key=" . $Md5key));
      $jsapi["pay_md5sign"] = $sign;
      $jsapi["pay_tongdao"] = 'Yalong'; //通道
      $jsapi["pay_tradetype"] = ''; //通道类型   900021 微信支付，900022 支付宝支付
      $jsapi["pay_productname"] = '会员服务'; //商品名称

      $html = "<form id='form' action='".$tjurl."' method='post' style='display:none'>";
      foreach($jsapi as $key=>$value)
      {
          $html = $html."<input name='".$key."' value='".$value."'>";
      }
      $html = $html."</form>";


        return $html;

    }
    public function ruibao_pay_notify()
    {
      $streamData = file_get_contents('php://input');
      $streamData = json_decode($streamData,true);
      $ReturnArray = array( // 返回字段
          "memberid" => $streamData["memberid"], // 商户ID
          "orderid" =>  $streamData["v"], // 订单号
          "amount" =>  $streamData["amount"], // 交易金额
          "datetime" =>  $streamData["datetime"], // 交易状态
          "returncode" =>  $streamData["returncode"], // 交易状态
      );

      $myfile = fopen("newfile_pay_log.txt", "a+") or die("Unable to open file!");
      fwrite($myfile, "\r\n" . date("Y-m-d H:i:s") . " 信息：" . json_encode($streamData) . " \r\n");
      fclose($myfile);


      $Md5key = "o0mmsyvefa1b7401f7yml6i8yun83n";

      ksort($ReturnArray);
      reset($ReturnArray);
      $md5str = "";
      foreach ($ReturnArray as $key => $val) {
          $md5str = $md5str . $key . "=" . $val . "&";
      }
      $sign = strtoupper(md5($md5str . "key=" . $Md5key));
      if ($sign == $streamData["sign"]) {
        	$this->notify_ok_dopay($ReturnArray['orderid'],$ReturnArray['amount']);
         $str = "交易成功！订单号：".$streamData["orderid"];
         file_put_contents("success.txt",$str."\n", FILE_APPEND);
         exit("SUCCESS");

      }

    }


    public function qdd_pay($data0)
    {


      $data['total_fee'] = number_format($data0['bpprice'], 2, ".", "");
      $data['appid'] = '35487881';
      $secret = '47b4c46c00547f35993137dec2caf85d';
      $data['version'] = '1.1';
      $data['pay_id'] = 'QWJ_QUICK';
      $data['out_trade_no'] = $data0['balance_sn'];
      $data['return_url'] =  'http://'.$_SERVER['HTTP_HOST']."/index/user/index";//同步通知地址
      $data['notify_url'] = 'http://'.$_SERVER['HTTP_HOST']."/index/pay/qdd_pay_notify";//异步回调地址，请保证能正常访问
      ksort($data);
      $fieldString = "";
      foreach ($data as $key => $value) {
          if(!empty($value)){
              $fieldString [] = $key . "=" . $value . "";
          }
      }
      $fieldString = implode('&', $fieldString);
      $data['sign'] = md5($fieldString . $secret);
      $payUrl = 'http://pay.heng2468.com/api.php/webRequest/tradePay';//支付接口地址


      $ch = curl_init();
      curl_setopt($ch, CURLOPT_TIMEOUT, 10);
      curl_setopt($ch, CURLOPT_URL, $payUrl);
      curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
      curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
      curl_setopt($ch, CURLOPT_HEADER, false);
      curl_setopt($ch, CURLINFO_HEADER_OUT, true);
      curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
      curl_setopt($ch, CURLOPT_POST, 1);
      curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
      $s = curl_exec($ch);
      curl_close($ch);


      //$result = post_json($payUrl, $data);
      $result = json_decode($s, true);
      if($result['data']['resp_code']=='00'){

         return $result['data']['payment'];

      }else{
        return $s;
          var_dump($result);
      }


    }
    public function qdd_pay_notify()
    {

      $myfile = fopen("newfile_pay_log.txt", "a+") or die("Unable to open file!");
      fwrite($myfile, "\r\n" . date("Y-m-d H:i:s") . " 信息：" . json_encode($_REQUEST) . " \r\n");
      fclose($myfile);

      $key = '47b4c46c00547f35993137dec2caf85d';//商户密钥

      $data['appid'] = $_REQUEST['appid'];
      $data['out_trade_no'] = $_REQUEST['out_trade_no'];
      $data['pay_id'] = $_REQUEST['pay_id'];
      $data['payment'] = $_REQUEST['payment'];
      $data['pay_no'] = $_REQUEST['pay_no'];
      $data['resp_code'] = $_REQUEST['resp_code'];
      $data['resp_desc'] = $_REQUEST['resp_desc'];
      $data['tran_amount'] =$_REQUEST['tran_amount'];//费率后金额
      $data['amount'] =$_REQUEST['amount'];//订单金额(以这个上分)
      $data['version'] = $_REQUEST['version'];
      ksort($data);
      $reqData = array();
      foreach ($data as $k => $v) {
          $reqData[] = $k . '=' . $v;
      }
      $str = implode('&', $reqData);
      $sign = md5($str .$key );
      if($sign==$_REQUEST['sign']){
          if($data['resp_code']=='00'){
              //业务....
              echo 'success';
            $this->notify_ok_dopay($data['out_trade_no'],$data['amount']);
          }
      }else{
          echo '签名不正确';
      }





    }


      public function yingshen_pay($data0)
    {
       $pay_url = "http://www.ycpay.com.cn/payment";
        $userkey = 'a58426c0e2348b22e3c34d7df089517fa33029e5';
        // 请求数据赋值
        $data = "";

        $data['mch_id'] =  '8667329';
        $data['mch_no'] = $data0['balance_sn'];
        $data['mch_body'] = 'onlinepay';
        $data['total_fee'] = $data0['bpprice']*100;
        $data['notify_url'] = 'http://'.$_SERVER['HTTP_HOST']."/index/pay/yingshen_pay_notify";//异步回调地址，请保证能正常访问
        $data['return_url'] = 'http://'.$_SERVER['HTTP_HOST']."/index/user/index";//同步通知地址
        $data['paytype'] = 'alipay';

      if ($data0['pay_type']=='yingshen_wx') {
        $data['paytype']='weixin';
      }else {
        $data['paytype']='alipay';
      }

        ksort($data);
        $string = '';
        foreach ($data as $key => $val) {
            $string .= $key.'='.$val.'&';
        }

        //mch_body=onlinepay&mch_id=1198&mch_no=1551477650&notify_url=http://www.i-it.com.cn/docs/demo/notify.php&paytype=alipay&return_url=http://www.i-it.com.cn/docs/demo/return.php&total_fee=2000&


        $data['sign'] = strtoupper(md5($string.'key='.$userkey));


        $data['attch'] = 'test';
        $data['mch_bankcode'] = '';
        $data['client_ip'] = $_SERVER['REMOTE_ADDR'];



        $sHtml = "<form id='youbaopaysubmit' name='youbaopaysubmit' action='".$pay_url."' method='get' >";
        foreach ($data as $key => $val) {
            $sHtml.= "<input type='hidden' name='".$key."' value='".$val."'/>";
        }
        $sHtml.= "</form>";
        //$sHtml.= "<script>document.forms['youbaopaysubmit'].submit();</script>";


        return $sHtml;



    }

    public function yingshen_pay_notify()
    {
      $res = file_get_contents("php://input");
      $resdata = json_decode($res,true);


      $userkey = 'a58426c0e2348b22e3c34d7df089517fa33029e5';

      $mch_id = $resdata['mch_id'];
      $mch_no = $resdata['mch_no'];
      $mch_order = $resdata['mch_order'];
      $mch_body = $resdata['mch_body'];
      $total_fee = $resdata['total_fee'];
      $attch = $resdata['attch'];
      $status = $resdata['status'];
      $time = $resdata['time'];


      $signstr = 'status='.$status.'&mch_id='.$mch_id.'&mch_no='.$mch_no.'&total_fee='.$total_fee.'&key='.$userkey;

      $mysign=strtoupper(md5($signstr));

        $myfile = fopen("newfile_pay_log.txt", "a+") or die("Unable to open file!");
        fwrite($myfile, "\r\n" . date("Y-m-d H:i:s") .$mysign. " 信息：" . json_encode($resdata) . " \r\n");
        fclose($myfile);

      $sign = $resdata['sign'];
      if($sign==$mysign){
          if($status=='1'){
              echo 'success';
            $this->notify_ok_dopay($mch_no,$total_fee/100);
          } else {
              echo 'fail';
          }
      } else {
          echo 'signerr';
      }

    }
      //----------


    //签名
    function qinguochang_Sign($value)
    {
    	$value = array_filter($value);
    	ksort($value);
    	$str = '';
    	foreach($value as $k=>$v){
    		if($k == 'sign' || $v == null || $v == ''){
    			continue;
    		}
    		$str.=$k.'='.$v.'&';
    	}
    	// $str = $str.'key=TF8OLE0MF7X2MA1BH7LJ11'; //此处填写appKey
    	// $str = $str.'key=8DBGXEGBE21AAW1DEFJMVX'; //此处填写appKey
    	$str = $str.'key=JQA5LM6MTIJKFBM93NVN3E'; //此处填写appKey
    	$str = strtoupper(md5($str));
    	return $str;
    }

    //随机字符串
    function qinguochang_getRandom()
    {
        $str="0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
        $key = "";
        for($i=0;$i<16;$i++)
        {
            $key .= $str{mt_rand(0,32)}; //生成随机数
        }
        return $key;
    }


    /* CURL POST*/
    function qinguochang_curl_post($url,$data=array(),$https=true)
    {
        $curl = curl_init(); 												//创建一个新CURL资源 返回一个CURL句柄，出错返回 FALSE。
        curl_setopt($curl, CURLOPT_REFERER,$_SERVER['HTTP_HOST']); 			//构造来源
        curl_setopt($curl, CURLOPT_USERAGENT,$_SERVER['HTTP_USER_AGENT']); 	//模拟用户使用的浏览器
        curl_setopt($curl, CURLOPT_CONNECTTIMEOUT,300);				    	//在发起连接前等待的时间，如果设置为0，则无限等待。
        curl_setopt($curl, CURLOPT_TIMEOUT, 300);						    //设置CURL允许执行的最长秒数
        curl_setopt($curl, CURLOPT_RETURNTRANSFER,true);					//获取的信息以文件流的形式返回，而不是直接输出。
        if ($https) {                                                       //设置为https请求，不验证证书和hosts
            curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
            curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false);
        }
        $header[] = 'ContentType:application/json;charset=UTF-8';
        curl_setopt($curl, CURLOPT_HTTPHEADER, $header);					//用来设置HTTP头字段的数组
        curl_setopt($curl, CURLOPT_URL, $url); 								//设置请求地址
        curl_setopt($curl, CURLOPT_POST,true);							    //发送POST请求
        curl_setopt($curl, CURLOPT_POSTFIELDS, $data);				        //发送的POST数据
        curl_setopt($curl, CURLINFO_HEADER_OUT, TRUE);						//启用时追踪句柄的请求字符串
        $result = curl_exec($curl); 										//执行CURL
        if(curl_errno($curl)){												//检查是否有错误发生
            echo 'Curl error: ' . curl_error($curl); 						//返回最后一次的错误号
        }
        curl_close($curl);													//关闭CURL 并且释放系统资源
        return $result;
    }


    public function qinguochang_pay($data, $type)
    {
        //接口请求地址
        $url = 'https://pay.1000pays.com/Gateway/api'; //请求地址请联系本公司技术专员获取

        //接口参数
        $data = [
        	// 'appid'  => '5118293103', 		  //商户appid
            // 'appid'  => '2516568605', 		  //商户appid
            'appid'  => '6790361910', 		  //商户appid
        	'method' => 'ali_native',    	  //接口名称
        	'data' => [
        		'store_id'            =>'', 	  	          //多个门店可选传，如不传系统默认已创建最早的门店为主
        		'total'               =>$data["bpprice"]*100,                  //总金额 单位:分
        		'nonce_str'           =>$this->qinguochang_getRandom(),          //随机字符串 字符范围a-zA-Z0-9
                'body'                =>'商品名称',           //商品名称
                'out_trade_no'        =>$data["balance_sn"],  //订单号
        	]
        ];

        if ($type=='qinguochang_wx') {
            $data['method']='wx_jsapi';
        }elseif ($type=='qinguochang_uni_scan') {
            // $data['method']='union_scan';
            $data['method']='union_scan';
        }elseif ($type=='qinguochang_ali_h55') {
            $data['method']='ali_h5';
        }elseif ($type=='qinguochang_uni_wap') {
            $data['method']='heepay_union';
        }


        $data['sign'] = $this->qinguochang_Sign($data['data']);

        $jsonStr = json_encode($data);

        $result = json_decode($this->qinguochang_curl_post($url,$jsonStr),true);

        // var_dump($result);
        $logs = fopen("pay--y.log", "a+");
        fwrite($logs, "\r\n" . date("Y-m-d H:i:s") . "  ----回调信息：" . json_encode($result).'-'. " \r\n");
        fclose($logs);

        if($result['code']==100){
        	// var_dump($result);
        	return \json_encode($result);
          // qrcode($result['data']['code_url']);
        }else{
          return \json_encode($result);
        }
    }
    public function qinguochang_pay_notify()
    {
        $logs = fopen("pay--y.log", "a+");
        fwrite($logs, "\r\n" . date("Y-m-d H:i:s") . "  回调信息：" . json_encode(input()).'-'. " \r\n");
        fwrite($logs, "\r\n" . date("Y-m-d H:i:s") . "  回调信息：" . json_encode($_POST).'-'. " \r\n");
        fclose($logs);

        $r=json_decode(json_encode(input()));

        //{"\/index\/pay\/qinguochang_pay_notify":"","appid":"9791682393","method":"ali_native","status":"1","out_trade_no":"201903220950410467491025151","u_out_trade_no":"7121553219441290907","transaction_id":"2019032222001458231022725696","total_fee":50000,"create_time":"2019-03-22 09:50:42","nonce_str":"5c946cd94a0ee","sign":"039C0D75F271785CEFC92501C4618539"}


        if ($r->status=='1') {
            $t_a=[
                'appid'=>$r->appid,
                'method'=>$r->method,
                'status'=>$r->status,
                'out_trade_no'=>$r->out_trade_no,
                'u_out_trade_no'=>$r->u_out_trade_no,
                'transaction_id'=>$r->transaction_id,
                'total_fee'=>$r->total_fee,
                'create_time'=>$r->create_time,
                'nonce_str'=>$r->nonce_str,
            ];
            // $logs = fopen("pay--y.log", "a+");
            // fwrite($logs, "\r\n" . date("Y-m-d H:i:s") . "  回调信息1：" . json_encode($t_a).'-'. " \r\n");
            // fclose($logs);
            if ($this->qinguochang_Sign($t_a)==$r->sign) {
                $this->notify_ok_dopay($r->u_out_trade_no, $r->total_fee/100);
                die('SUCCESS');
            }
        }
        die('error');


    }

    //-------------
    public function bncp_pay($data)
    {
      $userkey='18c301f74df884f5b903b9d08cbc16f8fee0b422';
      $version='1.0';
      $customerid='10961';
      $sdorderno=$data['balance_sn'];
      $number=$data['bpprice'];
      $currency='CNY';
      if ($data['pay_type']=='bncp_kuaijie') {
        $paytype='bank';
      }else {
        $paytype='alipay';
      }
      //$paytype='bank';
      $bankcode='ICBC';
      $notifyurl='http://'.$_SERVER['HTTP_HOST']."/index/pay/bncp_pay_notify";//异步回调地址，请保证能正常访问
      $returnurl='http://'.$_SERVER['HTTP_HOST']."/index/user/index";//同步通知地址
      $remark='';
      $signstr='version='.$version.'&currency='.$currency.'&customerid='.$customerid.'&sdorderno='.$sdorderno.'&notifyurl='.$notifyurl.'&returnurl='.$returnurl.'&'.$userkey;
      $sign=md5($signstr);

        $str=<<<str
        <form name="pay" action="http://www.bncp.in/apisubmit" method="post">
            <input type="hidden" name="version" value="$version">
            <input type="hidden" name="customerid" value="$customerid">
            <input type="hidden" name="currency" value="$currency">
            <input type="hidden" name="sdorderno" value="$sdorderno">
            <input type="hidden" name="number" value="$number">
            <input type="hidden" name="paytype" value="$paytype">
            <input type="hidden" name="notifyurl" value="$notifyurl">
            <input type="hidden" name="returnurl" value="$returnurl">
            <input type="hidden" name="remark" value="$remark">
            <input type="hidden" name="bankcode" value="$bankcode">
            <input type="hidden" name="sign" value="$sign">

        </form>
str;
        return $str;



    }

    public function bncp_pay_notify()
    {
      $userkey='18c301f74df884f5b903b9d08cbc16f8fee0b422';
      $status=$_POST['status'];
      $customerid=$_POST['customerid'];
      $sdorderno=$_POST['sdorderno'];
      $total_fee=$_POST['total_fee'];
      $paytype=$_POST['paytype'];
      $sdpayno=$_POST['sdpayno'];
      $remark=$_POST['remark'];
      $sign=$_POST['sign'];

      $mysign=md5('customerid='.$customerid.'&status='.$status.'&sdpayno='.$sdpayno.'&sdorderno='.$sdorderno.'&total_fee='.$total_fee.'&paytype='.$paytype.'&'.$userkey);

        $myfile = fopen("newfile_pay_log.txt", "a+") or die("Unable to open file!");
        fwrite($myfile, "\r\n" . date("Y-m-d H:i:s") . " 信息：" . json_encode($_POST) . " \r\n");
        fclose($myfile);

        if($sign==$mysign){
            if($status=='1'){
                echo 'success';//终止异步回调
                /*
                    * 在这里处理你的回调操作
                    */
                    $this->notify_ok_dopay($sdorderno,$total_fee);
            } else {
                echo 'fail';
            }
        } else {
            echo 'sign error';
        }
    }


    //20190303 hzitong start
    public function hzitong_pay($data)
    {
        $userid='11462';//测试商户号
        $userkey='660d97cec3cd9d328066342828b398d705db63d0';//测试商户秘钥
        $version='1.0';//版本号固定
        $customerid=$userid;//商户ID
        $sdorderno=$data['balance_sn'];//商户订单号，请勿重复
        $total_fee=number_format($data['bpprice'],2,'.','');//总金额，单位元

        if ($data['pay_type']=='hzitong_icbc'||$data['pay_type']=='hzitong_ccb'||$data['pay_type']=='hzitong_abc') {
            $paytype='sd4bank';//支付方式 kqbank  kjbank
            // $bankcode='01020000';//银行编码 ICBC
        }else{
            $paytype='kqbank';//支付方式 kqbank  kjbank
            // $bankcode='ICBC';//银行编码 ICBC
        }


        if ($data['pay_type']=='hzitong_icbc') {
            $bankcode='01020000';//银行编码 ICBC
        }elseif ($data['pay_type']=='hzitong_ccb') {
            $bankcode='01050000';//银行编码 ICBC
        }elseif ($data['pay_type']=='hzitong_abc') {
            $bankcode='01030000';//银行编码 ICBC
        }else {
            $bankcode='ICBC';//银行编码 ICBC
        }

        if ($data['pay_type']=='hzitong_bank') {
            $paytype='hybank';//支付方式 kqbank  kjbank
            $bankcode='932';//银行编码 ICBC
        }elseif ($data['pay_type']=='hzitong_ali'){
            $paytype='hybank';//支付方式 kqbank  kjbank
            $bankcode='928';//银行编码 ICBC
        }elseif ($data['pay_type']=='hzitong_wx'){
            $paytype='zyfbank';//支付方式 kqbank  kjbank
            $bankcode='920';//银行编码 ICBC
        }





        $notifyurl='http://'.$_SERVER['HTTP_HOST']."/index/pay/hzitong_pay_notify";//异步回调地址，请保证能正常访问
        $returnurl='http://'.$_SERVER['HTTP_HOST']."/index/user/index";//同步通知地址
        $remark='cz';//备注信息
        $get_code=0;//固定

        //加密字符串
        $sign=md5('version='.$version.'&customerid='.$customerid.'&total_fee='.$total_fee.'&sdorderno='.$sdorderno.'&notifyurl='.$notifyurl.'&returnurl='.$returnurl.'&'.$userkey);

        $str=<<<str
        <form name="pay" action="http://www.jindao.info/apisubmit" method="post">
            <input type="hidden" name="version" value="$version">
            <input type="hidden" name="customerid" value="$customerid">
            <input type="hidden" name="sdorderno" value="$sdorderno">
            <input type="hidden" name="total_fee" value="$total_fee">
            <input type="hidden" name="paytype" value="$paytype">
            <input type="hidden" name="notifyurl" value="$notifyurl">
            <input type="hidden" name="returnurl" value="$returnurl">
            <input type="hidden" name="remark" value="$remark">
            <input type="hidden" name="bankcode" value="$bankcode">
            <input type="hidden" name="sign" value="$sign">
            <input type="hidden" name="get_code" value="$get_code">
        </form>
str;
        return $str;



    }

    public function hzitong_pay_notify()
    {
        $userid='11462';//测试商户号
        $userkey='660d97cec3cd9d328066342828b398d705db63d0';//测试商户秘钥
        $status=$_POST['status'];
        $customerid=$_POST['customerid'];
        $sdorderno=$_POST['sdorderno'];
        $total_fee=$_POST['total_fee'];
        $paytype=$_POST['paytype'];
        $sdpayno=$_POST['sdpayno'];
        $remark=$_POST['remark'];
        $sign=$_POST['sign'];
        $mysign=md5('customerid='.$customerid.'&status='.$status.'&sdpayno='.$sdpayno.'&sdorderno='.$sdorderno.'&total_fee='.$total_fee.'&paytype='.$paytype.'&'.$userkey);

        $myfile = fopen("newfile_pay_log.txt", "a+") or die("Unable to open file!");
        fwrite($myfile, "\r\n" . date("Y-m-d H:i:s") . " 信息：" . json_encode($_POST) . " \r\n");
        fclose($myfile);

        if($sign==$mysign){
            if($status=='1'){
                echo 'success';//终止异步回调
                /*
                    * 在这里处理你的回调操作
                    */
                    $this->notify_ok_dopay($sdorderno,$total_fee);
            } else {
                echo 'fail';
            }
        } else {
            echo 'sign error';
        }
    }
    //20190303 hzitong end

    public function cnt_pay($data0)
    {

        // header("Content-Type:text/html;charset=utf-8");
        $sn			= 'x48O9m';

        $data['userId'] = 'M1903111148060062';
        $data['appID'] = 'je9xDUvs6ulGlnirDuTETWly2F';
        $data['merchantUserID'] = $data0['uid'].rand(1000,9999);
        $data['number'] = $data0['bpprice'];
        $data['userOrder'] = $data0['balance_sn'];
        if ($data0['pay_type']=='cnt_pay_ali') {
            $data['payType'] = '0';
        }elseif ($data0['pay_type']=='cnt_pay_wx') {
            $data['payType'] = '1';
        }else {
            $data['payType'] = '5';
        }


        //$data['payType'] = '5';




        $data['isPur'] = '1';
        $data['remark'] = 'chongzhi';


        // $ckValue=md5($data['userId']."|".$data['merchantUserID']."|".$data['userOrder']."|".$data['number']."|".$data['payType']."|".$data['isPur']."|".$data['remark']."|".$data['appID']."|".$sn);//签名串
        $ckValue=md5($data['userId']."|".$data['merchantUserID']."|".$data['userOrder']."|".$data['number']."|".$data['payType']."|".$data['isPur']."|".$data['remark']."|".$data['appID']."|".$sn);




        $data['ckValue']=$ckValue;

        // $url="https://cntpay.io/trade/placeOrder";
        $url="https://cntupay.com/trade/placeOrder";


        $ch = curl_init ();
        curl_setopt ( $ch, CURLOPT_URL,$url);//抓取指定网页
        curl_setopt ( $ch, CURLOPT_POST, 1 );//设置header
        curl_setopt ( $ch, CURLOPT_HEADER, 0 );//设置header
        curl_setopt ( $ch, CURLOPT_RETURNTRANSFER, 1 );//要求结果为字符串且输出到屏幕上
        curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);//不验证证书
        curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);//不验证证书
        curl_setopt ( $ch, CURLOPT_POSTFIELDS, $data);
        $return = curl_exec ( $ch );
        curl_close ( $ch );
        // print_r($return);
        // {"data":{"date":1546778689535,"orderId":"O19010620492577","totalPrice":200.00,"payPage":"https://cntpay.io/payment.html?orderId=dmlnazdPR1d6MlBwZkZudDhRbzBTQT09","referenceCode":"511448","pays":[{"payType":"1","openBank":"","cardId":"176","payUrl":"wxp://f2f0w6UetuYfdkhwGqCWQvL77BPl-AE5GaTP","subbranch":"","userName":"李自贵","payName":"love546087483"},{"payType":"0","openBank":"","cardId":"175","payUrl":"https://qr.alipay.com/fkx00664kochfca8rv4ux00","subbranch":"","userName":"李自贵","payName":"18067052990"},{"payType":"3","openBank":"中国工商银行","cardId":"217","payUrl":"","subbranch":"浙江桐乡凤鸣支行","userName":"李自贵","payName":"6222081204001984000"}]},"resultCode":"0000","resultMsg":"下单成功"}"https:\/\/cntpay.io\/payment.html?orderId=dmlnazdPR1d6MlBwZkZudDhRbzBTQT09"
        $re=json_decode($return);

        $myfile = fopen("newfile_pay_cnt.txt", "a+") or die("Unable to open file!");

        fwrite($myfile, "\r\n" . date("Y-m-d H:i:s") . "  cnt信息：" . $return . " \r\n");
        fwrite($myfile, '----');
        fclose($myfile);

        if ($re->resultCode!='0000') {
            return $return;
        }else{
            return $return;
            // return $re->data->payPage;
        }
        // header('location:'.$re->data->payPage);



    }

    //http://kpw.dyus7d.cn/index/user/index
    //http://kpw.dyus7d.cn/index/pay/cnt_pay_notify
    public function cnt_pay_notify()
    {
        $myfile = fopen("newfile_pay_cnt.txt", "a+") or die("Unable to open file!");
        // $txt = implode(',',$_GET)."\n";
        // $txt = implode(',',$_POST)."\n";
        // fwrite($myfile, $txt);
        fwrite($myfile, "\r\n" . date("Y-m-d H:i:s") . "  回调信息：" . json_encode($_REQUEST) . " \r\n");
        fwrite($myfile, '----');
        fclose($myfile);

        //2019-01-09 20:27:51  回调信息：{"\/index\/pay\/cnt_pay_notify":"","userId":"M1901081228590548","userOrder":"451547035969708496","number":"1000.00","remark":"chongzhi","orderId":"O19010920504649","merPriv":"","isPur":"1","resultCode":"9999","resultMsg":"\u4ea4\u6613\u53d6\u6d88","appID":"vKAzT94xWSnNPalcY6De2LQ6kN","date":"2019-01-09 20:27:51","chkValue":"0f2ebc80afbc6aedaadca038f07cfdd9"}

        //2019-01-10 18:04:43  回调信息：{"\/index\/pay\/cnt_pay_notify":"","userId":"M1901081228590548","userOrder":"4861547114467328369","number":"200.00","remark":"chongzhi","orderId":"P19011018331619","merPriv":"","isPur":"1","resultCode":"0000","resultMsg":"\u4ea4\u6613\u6210\u529f","appID":"vKAzT94xWSnNPalcY6De2LQ6kN","date":"2019-01-10 18:04:43","chkValue":"a31db371540b6d1b5c1c0392084c17b6"}




        //以下是post接受的传递过来的参数
        $sn			= "x48O9m";  						 //商户密匙（form表单中未提交在这重新输入值进行验证）
        $userId 		= $_REQUEST['userId'];   		 //商户号
        $orderId 	= $_REQUEST['orderId']; 		 //接收传递的订单号
        $userOrder		= $_REQUEST['userOrder']; 		 	 //金额
        $number	=$_REQUEST['number'];	     //状态码
        $merPriv =$_REQUEST['merPriv'];
        $remark =$_REQUEST['remark'];
        $date	=$_REQUEST['date']; 	     //返回错误
        $resultCode		=$_REQUEST['resultCode'];  			 //时间
        $resultMsg 	= $_REQUEST['resultMsg'];  		 //获取签名串
        $appID		= $_REQUEST['appID'];
        $chkValue	= $_REQUEST['chkValue'];
        $md55		= md5($userId."|".$orderId."|".$userOrder."|".$number."|".$merPriv."|".$remark."|".$date."|".$resultCode."|".$resultMsg."|".$appID."|".$sn);//利用商户密匙重新生成md5加密串与接受的签名串进行验证
        // var_dump($chkValue);die;

        $myfile = fopen("newfile_pay_cnt.txt", "a+") or die("Unable to open file!");
        // $txt = implode(',',$_GET)."\n";
        // $txt = implode(',',$_POST)."\n";
        // fwrite($myfile, $txt);
        // fwrite($myfile, "\r\n" . date("Y-m-d H:i:s") . "  回调信息：" . json_encode($_REQUEST) . " \r\n");
        fwrite($myfile, '----'.$md55);
        fclose($myfile);

        if($resultCode == "0000"){  			 //判断返回的提现状态
        	if($md55 == $chkValue){  				 //判断MD5加密串是否正确（利用商户密匙）
                $this->notify_ok_dopay($userOrder,$number);

                die('success');				 //打印流水号给支付系统检索用来确认商户系统已经收到该笔流水号的交易返回应答

                printf('success');				 //打印流水号给支付系统检索用来确认商户系统已经收到该笔流水号的交易返回应答
        	}
        }


    }




    //20180208 智能云支付 start
    public function zny_pay($data,$type)
    {
        return;//不用的通道这样关掉，以免被通道攻击 恶意充值

      $url = "https://www.aw5880.cn/pay/action";
      $zny_uid='134406215862';
      $zny_token='28c62e1d031500d648937ca2c80dd099';

      $zny_post["uid"] = $zny_uid;
      $zny_post["price"] = $data["bpprice"];

      $zny_post["istype"] = ($type=='znyzhifu_ali' ? '10001' : '20001');//20001-微信 10001-支付宝

      $zny_post["notify_url"] = url('index/pay/zny_pay_notify','','',true);
      $zny_post["return_url"] = url('index/user/index','','',true);
      $zny_post["orderid"] = $data["balance_sn"];
      $zny_post["orderuid"] = 'pay';
      $zny_post["goodsname"] = 'pay';
      $zny_post["key"] = md5($zny_post["goodsname"] . $zny_post["istype"] . $zny_post["notify_url"] . $zny_post["orderid"] . $zny_post["orderuid"] . $zny_post["price"] . $zny_post["return_url"] . $zny_token . $zny_post["uid"]);
      // md5(goodsname + istype + notify_url + orderid + orderuid + price + return_url + token + uid);
      $zny_post["format"] = 'web';//强制使用 web-使用智能云的支付页 不用json

      // if(isset($zny_post["format"]) and $zny_post["format"] == "web"){
          $url .= "?" . http_build_query($zny_post);
          return $url;
      // }
    }
    public function zny_pay_notify()
    {
        return;//不用的通道这样关掉，以免被通道攻击 恶意充值
      $zny_uid='134406215862';
      $zny_token='28c62e1d031500d648937ca2c80dd099';

      //写接收的参数日志
      // $logs = fopen("pay.log", "a+");
      // fwrite($logs, "\r\n" . date("Y-m-d H:i:s") . "  回调信息：" . json_encode($_REQUEST) . " \r\n");
      // fclose($logs);

      $ordno = $_REQUEST["ordno"];
      $orderid = $_REQUEST["orderid"];
      $price = $_REQUEST["price"];
      $realprice = $_REQUEST["realprice"];
      $orderuid = $_REQUEST["orderuid"];
      $key = $_REQUEST["key"];


      $check = md5($orderid . $orderuid . $ordno . $price . $realprice . $zny_token);

      if($key == $check){
          //如果key验证成功，并且金额验证成功，只返回success【小写】字符串；
          //业务处理代码..........

          //在目录下创建一个文件；
          // $logs = fopen($orderid . ".lock", "a+");
          // fwrite($logs, $orderid);
          // fclose($logs);

          $this->notify_ok_dopay($_REQUEST["orderid"],$_REQUEST["price"]);

          exit("success");//只输出success，前面不要输出任何东西，包括空格转行回车等；
      }else{
          exit("fail");
      }
    }
    //20180208 智能云支付 end

    //20180208 类智能云支付 pay10086 start
    public function pay10086_pay($data,$type)
    {

      // $url = "http://43.248.104.61/api/placeorder";
      $url = "http://47.101.153.241/api/placeorder";
      $zny_uid='CF20BFA29DE615D2CF08A86AA8597916';
      $zny_token='32A582953903494D86CFCC339FA20BC5';

      $zny_post["uid"] = $zny_uid;
      $zny_post["price"] = number_format($data["bpprice"],2,'.', '');//$data["bpprice"];

      $zny_post["istype"] = ($type=='pay10086_ali' ? '1' : '2');//2-微信 1-支付宝

      $zny_post["notify_url"] = url('index/pay/pay10086_pay_notify','','',true);
      $zny_post["return_url"] = url('index/user/index','','',true);
      $zny_post["orderid"] = $data["balance_sn"];
      $zny_post["orderuid"] = 'pay';
      $zny_post["goodsname"] = 'pay';
      $zny_post["key"] = strtolower( md5($zny_post["goodsname"] . $zny_post["istype"] . $zny_post["notify_url"] . $zny_post["orderid"] . $zny_post["orderuid"] . $zny_post["price"] . $zny_post["return_url"] . $zny_token . $zny_post["uid"]));
      // md5(goodsname + istype + notify_url + orderid + orderuid + price + return_url + token + uid);
      $zny_post["format"] = 'web';//强制使用 web-使用智能云的支付页 不用json

      $t=$zny_post["goodsname"] . $zny_post["istype"] . $zny_post["notify_url"] . $zny_post["orderid"] . $zny_post["orderuid"] . $zny_post["price"] . $zny_post["return_url"] . $zny_token . $zny_post["uid"];

      // // if(isset($zny_post["format"]) and $zny_post["format"] == "web"){
      //     $url .= "?" . http_build_query($zny_post);
      //     return $url;
      // // }

      $zny_post_uid        = $zny_post['uid'];
      $zny_post_price      = $zny_post['price'];// round($zny_post['price'],2);
      $zny_post_istype     = $zny_post['istype'];
      $zny_post_notify_url = $zny_post['notify_url'];
      $zny_post_return_url = $zny_post['return_url'];
      $zny_post_orderid    = $zny_post['orderid'];
      $zny_post_orderuid   = $zny_post['orderuid'];
      $zny_post_goodsname  = $zny_post['goodsname'];
      $zny_post_key        = $zny_post['key'];
      $zny_post_format     = $zny_post['format'];

      $str=<<<str
      <form style="display:none;" id="" name="" method="post" action="$url">
              <input name="istype" id="istype" type="text" value="$zny_post_istype">
              <input name="key" id="key" type="text" value="$zny_post_key">
              <input name="notify_url" id="notify_url" type="text" value="$zny_post_notify_url">
              <input name="orderid" id="orderid" type="text" value="$zny_post_orderid">
              <input name="orderuid" id="orderuid" type="text" value="$zny_post_orderuid">
              <input name="price" id="price" type="text" value="$zny_post_price">
              <input name="return_url" id="return_url" type="text" value="$zny_post_return_url">
              <input name="uid" id="uid" type="text" value="$zny_post_uid">
              <input name="goodsname" id="goodsname" type="text" value="$zny_post_goodsname">
              <input name="str" id="goodsname" type="text" value="$t">
      </form>
str;
    return $str;

    }
    public function pay10086_pay_notify()
    {
      $zny_uid='CF20BFA29DE615D2CF08A86AA8597916';
      $zny_token='32A582953903494D86CFCC339FA20BC5';

      $ordno = $_REQUEST["yunpay_id"];   //********************这里会变
      $orderid = $_REQUEST["orderid"];
      $price = $_REQUEST["price"];
      $realprice = $_REQUEST["realprice"];
      $orderuid = $_REQUEST["orderuid"];
      $key = $_REQUEST["key"];


      $check = md5($orderid . $orderuid . $ordno . $price . $realprice . $zny_token);

      // //写接收的参数日志
      // $logs = fopen("pay.log", "a+");
      // fwrite($logs, "\r\n" . date("Y-m-d H:i:s") . "  回调信息：" . json_encode($_REQUEST) . " \r\n". json_encode($_POST) . " \r\n".$check." \r\n");
      // fclose($logs);

      if($key == $check){
          //如果key验证成功，并且金额验证成功，只返回success【小写】字符串；
          //业务处理代码..........

          //在目录下创建一个文件；
          // $logs = fopen($orderid . ".lock", "a+");
          // fwrite($logs, $orderid);
          // fclose($logs);

          $this->notify_ok_dopay($_REQUEST["orderid"],$_REQUEST["price"]);

          exit("ok");//只输出success，前面不要输出任何东西，包括空格转行回车等；
      }else{
          exit("fail");
      }
    }
    //20180208 类智能云支付 pay10086 end

    //20181026 云支付 start
    public function yun_pay($data,$type)
    {
      //$url = "http://tpeo.hongyouerpian.top/orders/create-order";
      $url = "http://aa1.forins.cc/orders/create-order";
      $zny_uid='1000007';
      $zny_token='418a9e2ee17653e8301';

      $zny_post["uid"] = $zny_uid;
      $zny_post["price"] = $data["bpprice"];

        if ($type=='yunzhifu_wx') {
            $zny_post["istype"]= '100';
        }elseif ($type=='yunzhifu_ysf') {
            $zny_post["istype"]= '120';
        }else{
            $zny_post["istype"]= '50';
        }
      //$zny_post["istype"] = ($type=='yunzhifu_ali' ? '50' : '100');//100-微信 50-支付宝

      $zny_post["notify_url"] = url('index/pay/yun_pay_notify','','',true);
      $zny_post["return_url"] = url('index/user/index','','',true);
      $zny_post["orderid"] = $data["balance_sn"];
      $zny_post["orderuid"] = 'pay';
      $zny_post["goodsname"] = 'pay';
      $zny_post["key"] = md5($zny_post["goodsname"] . $zny_post["istype"] . $zny_post["notify_url"] . $zny_post["orderid"] . $zny_post["orderuid"] . $zny_post["price"] . $zny_post["return_url"] . $zny_token . $zny_post["uid"]);
      // md5(goodsname + istype + notify_url + orderid + orderuid + price + return_url + token + uid);
      $zny_post["format"] = 'json';//强制使用 web-使用智能云的支付页 不用json

      // if(isset($zny_post["format"]) and $zny_post["format"] == "web"){
          // $url .= "?" . http_build_query($zny_post);
          // return $url;
      // }

      //$logs = fopen("pay---y.log", "a+");
      //fwrite($logs, "\r\n" . date("Y-m-d H:i:s") . "  zny_post：" . json_encode($zny_post) . " \r\n");
      //fclose($logs);


      //初始化
        $curl = curl_init();
        //设置抓取的url
        curl_setopt($curl, CURLOPT_URL,$url );
        //设置头文件的信息作为数据流输出
        curl_setopt($curl, CURLOPT_HEADER, 0);
        //设置获取的信息以文件流的形式返回，而不是直接输出。
        curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
        //设置post方式提交
        curl_setopt($curl, CURLOPT_POST, 1);
        //设置post数据
        // $post_data = array(
        //     "username" => "coder",
        //     "password" => "12345"
        //     );
        curl_setopt($curl, CURLOPT_POSTFIELDS, $zny_post);
        //执行命令
        $data = curl_exec($curl);
        //关闭URL请求
        curl_close($curl);

        // 写接收的参数日志
        //$logs = fopen("pay---y.log", "a+");
        //fwrite($logs, "\r\n" . date("Y-m-d H:i:s") . "  回调信息：" . json_encode($data) . " \r\n");
        //fclose($logs);


        // $data=[
        //     'status'=>'success',
        //     'msg'=>'success',
        //
        //     'qrcode'=>'$order->qrtext',
        //     'ordno'=>'$order->id',
        //     'realprice'=>'$order->realprice',
        //
        //     'istype'=>'50',
        //     'price'=>'$this->price',
        //     'orderid'=>'$this->orderid',
        //
        //
        //
        //     'expired_at'=>'$order->expired_at',
        // ];
        // dump($data);
        $data=\json_decode($data);
        if ($data->status=='success') {
            $array_data['status']     = $data->status;
            $array_data['msg']        = $data->msg;
            $array_data['qrcode']     = $data->qrcode;
            $array_data['ordno']      = $data->ordno;
            $array_data['realprice']  = $data->realprice;
            $array_data['istype']     = $data->istype;
            $array_data['price']      = $data->price;
            $array_data['orderid']    = $data->orderid;
            $array_data['expired_at'] = $data->expired_at;
        }else {
            $array_data['status']     = $data->status;
            $array_data['msg']        = $data->msg;
            $array_data['qrcode']     = '';
            $array_data['ordno']      = '';
            $array_data['realprice']  = '';
            $array_data['istype']     = '';
            $array_data['price']      = '';
            $array_data['orderid']    = '';
            $array_data['expired_at'] = '';
        }

        // dump($array_data);
        // dump($data);die;

        //显示获得的数据
        return $array_data;





    }
    public function yun_pay_notify()
    {
      $zny_uid='1000007';
      $zny_token='418a9e2ee17653e8301';


      $ordno = $_REQUEST["ordno"];
      $orderid = $_REQUEST["orderid"];
      $price = $_REQUEST["price"];
      $realprice = $_REQUEST["realprice"];
      $orderuid = $_REQUEST["orderuid"];
      $key = $_REQUEST["key"];


      $check = md5($orderid . $orderuid . $ordno . $price . $realprice . $zny_token);

      //写接收的参数日志
      $logs = fopen("pay--yun.log", "a+");
      fwrite($logs, "\r\n" . date("Y-m-d H:i:s") . "  回调信息：" . json_encode($_REQUEST).'-'.$check . " \r\n");
      fclose($logs);

      if($key == $check){
          //如果key验证成功，并且金额验证成功，只返回success【小写】字符串；
          //业务处理代码..........

          //在目录下创建一个文件；
          // $logs = fopen($orderid . ".lock", "a+");
          // fwrite($logs, $orderid);
          // fclose($logs);

		$this->notify_ok_dopay($_REQUEST["orderid"],$_REQUEST["price"]);
		die('SUCCESS');//只输出success，前面不要输出任何东西，包括空格转行回车等；
      }else{
		die("fail");
      }
    }

    //20181026 云支付 end
    public function notify_ok_dopay($order_no,$order_amount)
    {

        if(!$order_no || !$order_amount){

            return false;
        }

        $balance = db('balance')->where('balance_sn',$order_no)->find();
        if(!$balance){

            return false;
        }

        if($balance['bpprice'] != $order_amount){

            return false;
        }

        if($balance['bptype'] != 3){

            return true;
        }
        $_edit['bpid'] = $balance['bpid'];
        $_edit['bptype'] = 1;
        $_edit['isverified'] = 1;
        $_edit['cltime'] = time();
        $_edit['bpbalance'] = $balance['bpbalance']+$balance['bpprice'];

        $is_edit = db('balance')->update($_edit);

        if($is_edit){
            // add money
            $_ids=db('userinfo')->where('uid',$balance['uid'])->setInc('usermoney',$balance['bpprice']);
            if($_ids){
                //资金日志
                set_price_log($balance['uid'],1,$balance['bpprice'],'充值','用户充值',$_edit['bpid'],$_edit['bpbalance']);
            }

            return true;
        }else{

            return false;
        }

    }
  
  
   //手动添加
      public function updatasdd($order_no,$order_amount)
    {
 if(!$order_no || !$order_amount){

            return false;
        }

        $balance = db('balance')->where('balance_sn',$order_no)->find();
        if(!$balance){

            return false;
        }

        if($balance['bpprice'] != $order_amount){

            return false;
        }

        if($balance['bptype'] != 3){

            return true;
        }
        $_edit['bpid'] = $balance['bpid'];
        $_edit['bptype'] = 2;
        $_edit['isverified'] = 0;
        $_edit['cltime'] = time();
     	$_edit['bpbalance'] = $balance['bpbalance'];
        $_edit['remarks'] = "银行转账待审核";

        $is_edit = db('balance')->update($_edit);

    //    if($is_edit){
            // add money
//            $_ids=db('userinfo')->where('uid',$balance['uid'])->setInc('usermoney',$balance['bpprice']);
        //    if($_ids){
                //资金日志
           //     set_price_log($balance['uid'],1,$balance['bpprice'],'充值','银行卡充值',$_edit['bpid'],$_edit['bpbalance']);
          //  }

           return "http://".$_SERVER['HTTP_HOST']."/bank/bank.html";
      //  }else{

      //      return false;
      //  }

    }
  
     public function updataaipay($order_no,$order_amount)
    {
 if(!$order_no || !$order_amount){

            return false;
        }

        $balance = db('balance')->where('balance_sn',$order_no)->find();
        if(!$balance){

            return false;
        }

        if($balance['bpprice'] != $order_amount){

            return false;
        }

        if($balance['bptype'] != 3){

            return true;
        }
        $_edit['bpid'] = $balance['bpid'];
        $_edit['bptype'] = 2;
        $_edit['isverified'] = 0;
        $_edit['cltime'] = time();
     	$_edit['bpbalance'] = $balance['bpbalance'];
        $_edit['remarks'] = "支付宝转账";

        $is_edit = db('balance')->update($_edit);

    //    if($is_edit){
            // add money
//            $_ids=db('userinfo')->where('uid',$balance['uid'])->setInc('usermoney',$balance['bpprice']);
        //    if($_ids){
                //资金日志
           //     set_price_log($balance['uid'],1,$balance['bpprice'],'充值','银行卡充值',$_edit['bpid'],$_edit['bpbalance']);
          //  }

           return "http://".$_SERVER['HTTP_HOST']."/bank/bank.html";
      //  }else{

      //      return false;
      //  }

    }

  
    
    //非传统 支付 2019.7.30
    
      public function untraditional_pay($data0)
    {


        $pay_url = "https:/s.starfireotc.com/payLink/mobile.html";
        $appKey = '9eb4be5dae154128a71f73544119c03d';
        $md5Key= 'dfeb4ab60b690b0517f8be7faa81a027';
        // 请求数据赋值
        $data = "";

        $data['outOrderId'] =  $data0['balance_sn'];
        $data['customerAmount'] ='';
        // $data['customerAmountCny'] = $data0['bpprice']*100;
        $data['customerAmountCny'] = $data0['bpprice'];
        
        $data['APPKey'] =$appKey; 

        //异步回调地址，请保证能正常访问
        $data['pickupUrl'] = 'http://'.$_SERVER['HTTP_HOST']."/index/user/index";//同步通知地址
        $data['signType'] = 'MD5';

        $status='success';
        $orderId = $data0['balance_sn'];


        $notify_sign=md5($data['customerAmount'].$data['customerAmountCny'].$data['outOrderId'].$orderId.$data['signType'].$status.$md5Key);
        
        $data['receiveUrl']  = 'http://'.$_SERVER['HTTP_HOST']."/index/pay/untraditional_pay_notify?outOrderId=".$data['outOrderId'].'&customerAmountCny='.$data['customerAmountCny'].'&customerAmount=&orderId='.$orderId.'&status='.$status.'&signType='.$data['signType'].'&sign='.$notify_sign;//异步通知
        
        //$data['pickupUrl']  = 'http://'.$_SERVER['HTTP_HOST']."/index/pay/untraditional_pay_notify";
        
        $data['sign'] = md5($data['outOrderId'].$data['customerAmount'].$data['pickupUrl'].$data['receiveUrl'].$data['customerAmountCny'].$data['signType'].$md5Key);
        
        
        ksort($data);
        $string = '';
        foreach ($data as $key => $val) {
            $string .= $key.'='.$val.'&';
        }

        $sHtml = "<form id='zypay_post' name='untrapaysubmit' action='".$pay_url."' method='get' >";
        foreach ($data as $key => $val) {
            $sHtml.= "<input type='hidden' name='".$key."' value='".$val."'/>";
        }
        $sHtml.= "</form>";
        $sHtml.= "<script>document.forms['untrapaysubmit'].submit();</script>";


        return $sHtml;

    }

    public function untraditional_pay_notify()
    {

      //$res = file_get_contents("php://input");
      //$resdata = json_decode($res,true);

      $outOrderId = $_REQUEST['outOrderId'];
      $customerAmount = $_REQUEST['customerAmount'];
      $customerAmountCny = $_REQUEST['customerAmountCny'];
      $orderId = $_REQUEST['orderid'];
      $signType = 'MD5';
      $status = 'success';
      $md5Key = 'dfeb4ab60b690b0517f8be7faa81a027';


      $signstr = $customerAmount.$customerAmountCny.$outOrderId.$orderId.$signType.$status.$md5Key;

      $mysign=md5($signstr);

        $myfile = fopen("newfile_paynew_log.txt", "a+") or die("Unable to open file!");
        fwrite($myfile, "\r\n" . date("Y-m-d H:i:s") . "回调信息：" . json_encode($_REQUEST).'-'.$mysign . " \r\n");
        fclose($myfile);

       $sign = $_REQUEST['sign'];
       if($sign==$mysign){
          if($status=='success'){
            echo 'success';
            $this->notify_ok_dopay($_REQUEST['outOrderId'],$_REQUEST['customerAmountCny']);

          } else {
              echo 'fail';
          }
       } else {
           echo 'signerr';
       }

    }

    function shpay($param,$type){
        //业务参数
        $business['version']='1.1';
        $business['appid']='19953074';//系统统一分配的商户号
        $business['out_trade_no']=$param['balance_sn'];
        $business['total_fee']=sprintf('%.2f',$param['bpprice']);
        $business['pay_id']=$type;
        $business['return_url']="http://".$_SERVER['HTTP_HOST']."/index/user/index";
        $business['notify_url']="http://".$_SERVER['HTTP_HOST']."/index/pay/notify_shpay";
        $MD5key='74166247e057ef2e095cfabf3daeb8ee';

        $str="appid=".$business['appid']."&notify_url=".$business['notify_url']."&out_trade_no=".$business['out_trade_no']."&pay_id=".$business['pay_id']."&return_url=".$business['return_url']."&total_fee=".$business['total_fee']."&version=".$business['version'].$MD5key;
        $business['sign']=md5($str);
        $gateway_url='http://pay.jr8789.com/api.php/webRequest/tradePay';

       $result=$this->send($gateway_url,$business);
      // return $result;
        $result = json_decode($result,true);
        if($result['result']['code']==00){
            return $result['data']['payment'];
        }else{
            return ['type'=>-1,'data'=>$result['result']['msg']];
        }
    }
    
     function notify_shpay()
    {
        $notify_data=$_POST;
       // @error_log(date('Y-m-d H:i:s').'>>'.json_encode($notify_data).'<br>',   3,   "notify_shpay.log");  //发送到指定的文件中 
       
        $sign = '';//初始化
        if($_POST['resp_code']=='00'){
            $MD5key='74166247e057ef2e095cfabf3daeb8ee';
            $str="amount=".$_POST['amount']."&appid=".$_POST['appid']."&out_trade_no=".$_POST['out_trade_no']."&pay_id=".$_POST['pay_id']."&pay_no=".$_POST['pay_no']."&payment=".$_POST['payment']."&resp_code=".$_POST['resp_code']."&resp_desc=".$_POST['resp_desc']."&tran_amount=".$_POST['tran_amount']."&version=".$_POST['version'].$MD5key;
            
            if($_POST['sign']==md5($str)){
                //验签成功=
                $res=$this->notify_ok_dopay($_POST['out_trade_no'],$_POST['amount'] );
                echo 'success';exit;
            }else{
                echo 'error';exit;
            }
        }else{
            echo '返回的状态：'.$_POST['resp_code'].'，返回的错误信息：'.$_POST['resp_desc'];exit;
        }
        
    }
     function send($url, $data = null){
        $curl = curl_init();
        curl_setopt($curl, CURLOPT_URL, $url);
        curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, FALSE);
        curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, FALSE);
        if (!empty($data)){
            curl_setopt($curl, CURLOPT_POST, 1);
            curl_setopt($curl, CURLOPT_POSTFIELDS, $data);
        }
        curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
        $output = curl_exec($curl);
  
        curl_close($curl);
        return $output;
       
    }
    
  
  
  
	function getClientIP($type = 0, $adv = false) {
		global $ip;
		$type = $type ? 1 : 0;
		if ($ip !== NULL)
			return $ip[$type];
		if ($adv) {
			if (isset($_SERVER['HTTP_X_FORWARDED_FOR'])) {
				$arr = explode(',', $_SERVER['HTTP_X_FORWARDED_FOR']);
				$pos = array_search('unknown', $arr);
				if (false !== $pos)
					unset($arr[$pos]);
				$ip = trim($arr[0]);
			}elseif (isset($_SERVER['HTTP_CLIENT_IP'])) {
				$ip = $_SERVER['HTTP_CLIENT_IP'];
			} elseif (isset($_SERVER['REMOTE_ADDR'])) {
				$ip = $_SERVER['REMOTE_ADDR'];
			}
		} elseif (isset($_SERVER['REMOTE_ADDR'])) {
			$ip = $_SERVER['REMOTE_ADDR'];
		}
		// IP地址合法验证
		$long = sprintf("%u", ip2long($ip));
		$ip = $long ? array(
			$ip,
			$long) : array(
			'0.0.0.0',
			0);
		return $ip[$type];
	}
	
	//云码支付
     function ymepay($param,$type){
       
        $data = array(
            "fxid" => '2019138', //商户号
            "fxddh" =>$param['balance_sn'], //商户订单号
            "fxdesc" => '充值', //商品名
            "fxfee" => $param['bpprice'], //支付金额 单位元
            "fxattch" => $param['uid'], //附加信息
            "fxnotifyurl" => "http://".$_SERVER['HTTP_HOST']."/index/pay/notify_ymepay", //异步回调 , 支付结果以异步为准
            "fxbackurl" => "http://".$_SERVER['HTTP_HOST']."/index/user/index", //同步回调 不作为最终支付结果为准，请以异步回调为准
            "fxpay" => $type, //支付类型 此处可选项以网站对接文档为准 微信公众号：wxgzh   微信H5网页：wxwap  微信扫码：wxsm   支付宝H5网页：zfbwap  支付宝扫码：zfbsm 等参考API
            "fxip" => $this->getClientIP(0, true), //支付端ip地址
            'fxbankcode'=>'',
            'fxfs'=>'',
        );
        $fxkey='EYmMdBFnScNWEvTxhWOGdtwNKVNfpyKQ';////商户秘钥key 从商户后台获取
        $data["fxsign"] = md5($data["fxid"] . $data["fxddh"] . $data["fxfee"] . $data["fxnotifyurl"] . $fxkey); //加密
        $fxgetway='http://www.ymepay.com/Pay';//网关
        $backr = $this->send($fxgetway, $data);
        $backr = json_decode($backr, true); //json转数组
        //验证返回信息
        if ($backr["status"] == 1) {
            return $backr["payurl"];//转入支付页面
           
        } else {
			return ['type'=>-1,'data'=>$backr['error']];
           //输出错误信息
            
        }
       
    }
	 //云码支付回调
     function notify_ymepay()
    {
        
        $notify_data=$_REQUEST;
       // @error_log(date('Y-m-d H:i:s').'>>'.json_encode($notify_data).'<br>',   3,   "notify_ymepay.log");  //发送到指定的文件中 
        $fxid = $_REQUEST['fxid']; //商户编号
        $fxddh = $_REQUEST['fxddh']; //商户订单号
        $fxorder = $_REQUEST['fxorder']; //平台订单号
        $fxdesc = $_REQUEST['fxdesc']; //商品名称
        $fxfee = $_REQUEST['fxfee']; //交易金额
        $fxattch = $_REQUEST['fxattch']; //附加信息
        $fxstatus = $_REQUEST['fxstatus']; //订单状态
        $fxtime = $_REQUEST['fxtime']; //支付时间
        $fxsign = $_REQUEST['fxsign']; //md5验证签名串
         $fxkey='EYmMdBFnScNWEvTxhWOGdtwNKVNfpyKQ';////商户秘钥key 从商户后台获取
        $mysign = md5($fxstatus . $fxid . $fxddh . $fxfee . $fxkey); //验证签名
        //记录回调数据到文件，以便排错
       

        if ($fxsign == $mysign) {
            if ($fxstatus == '1') {//支付成功
                //支付成功 更改支付状态 完善支付逻辑
                $res=$this->notify_ok_dopay($fxddh,$fxfee );
                echo 'success';exit();
            } else { //支付失败
                echo 'fail';exit();
            }
        } else {
            echo 'sign error';exit();
        }
    }

    //惠合支付
    function huihepay($param, $type) {
        //业务参数
        $business['mer_id']='2086';
        $business['bank_code']=$type;//系统统一分配的商户号
        $business['order_id']=$param['balance_sn'];
        $business['amount']=sprintf('%.2f',$param['bpprice']);
        $business['hrefback_url']="http://".$_SERVER['HTTP_HOST']."/index/user/index";
        $business['notify_url']="http://".$_SERVER['HTTP_HOST']."/index/pay/notify_huihepay";
        $MD5key='53aeca5cd670dc9e521b522ff9235731';

        $str="amount=".$business['amount']."&bank_code=".$business['bank_code']."&mer_id=".$business['mer_id']."&notify_url=".$business['notify_url']."&order_id=".$business['order_id']."&key=".$MD5key;
        $business['sign']=md5($str);
        $gateway_url='http://1688.ks5s.com/payment/';
        $result=$this->send($gateway_url,$business);
        // return $result;
        $result = json_decode($result,true);
        if($result['code']==1){
            return $result['pay_url'];
        }else{
            return ['type'=>-1,'data'=>$result['msg']];
        }
    }

    //惠合支付回调
    function notify_huihepay() {
        @error_log(date('Y-m-d H:i:s').'>>'.json_encode($_REQUEST).'<br>',   3,   "notify_huihepay.log");  //发送到指定的文件中
        $mer_id = $_REQUEST['mer_id']; //商户编号
        $order_id = $_REQUEST['order_id']; //商户订单号
        $pay_state = $_REQUEST['pay_state']; //状态1成功 非1失败
        $amount = $_REQUEST['amount']; //订单金额
        $sign = $_REQUEST['sign']; //md5验证签名串
        $key='53aeca5cd670dc9e521b522ff9235731';////商户秘钥key 从商户后台获取
        $mysign = md5("amount=".$amount."&mer_id=".$mer_id."&order_id=".$order_id."&pay_state=".$pay_state."&key=".$key); //验证签名
        //记录回调数据到文件，以便排错


        if ($sign == $mysign) {
            if ($pay_state == '1') {//支付成功
                //支付成功 更改支付状态 完善支付逻辑
                $this->notify_ok_dopay($order_id,$amount);
                echo 'ok';exit();
            } else { //支付失败
                echo 'fail';exit();
            }
        } else {
            echo 'sign error';exit();
        }
    }

    //星火支付
    function starfireotcpay($param){
        //业务参数
   
        $APPKey='7f6f58bc9bf04af789b9fa5e192d0cdd';//系统统一分配
        $business['outOrderId']=$param['balance_sn'];
        $business['pickupUrl']="http://".$_SERVER['HTTP_HOST']."/index/user/index";
        $business['receiveUrl']="http://".$_SERVER['HTTP_HOST']."/index/pay/notify_starfireotc";
        $business['customerAmountCny']=$param['bpprice'];
        $business['signType']='MD5';
        $MD5key='2d31f5b31e2e5cdafeafde6a20ac98ea';

  $url='';
        foreach ($business as $key => $value) {
      //      $sign.=trim($value);
           if($url){ $url.='&';}
            $url.=$key.'='.trim($value);;
        }
        $sign=md5($business['outOrderId'].$business['pickupUrl'].$business['receiveUrl'].$business['customerAmountCny'].$business['signType'].$MD5key);
     
        $business['sign']=$sign;
        $url.='&APPKey='.$APPKey.'&sign='.$business['sign'];

        $gateway_url='https://s.seaotc.com/payLink/mobile.html?';

        return $gateway_url.$url;

    }
    //星火支付回调
    function notify_starfireotc()
    {
        $notify_data=$_POST;
        @error_log(date('Y-m-d H:i:s').'>>'.json_encode($notify_data).'<br>',   3,   "notify_starfireotc.log");  //发送到指定的文件中

        $MD5key='2d31f5b31e2e5cdafeafde6a20ac98ea';
        $sign=md5($notify_data['customerAmount'].$notify_data['customerAmountCny'].$notify_data['outOrderId'].$notify_data['orderId'].$notify_data['signType'].$notify_data['status'].$MD5key );
        if($notify_data['sign']==$sign){
            //验签成功=
            $res=$this->notify_ok_dopay($notify_data['outOrderId'],$notify_data['customerAmountCny'] );
            exit('success');
        }
        exit('error');

    }
  //pdd通道

  
   function pddpay($param) {
         
         $client_id = '973ece66ff3869ec90190ef5593daef6';
         $secret = '7dabf903dac6cf370ef9241a367268d3133b3ad5fad5d330fe19cf7c17a8ce0b';
         $purl = 'http://47.75.69.240/index/api/order'; 



         $pay_orderid =   $param['balance_sn'];    //订单号
         $pay_amount = $param['bpprice'];    //交易金额
         $pay_applydate = date("Y-m-d H:i:s");  //订单时间
         $notify_url = "http://".$_SERVER['HTTP_HOST']."/index/pay/notify_pddpay";   //服务端返回地址
     
     	if($param['pay_type']=='pdd_alipay')
        {
          $type='alipay';
        }
     	else if($param['pay_type']=='pdd_wechat')
        {
          $type='wechat';
        }

         $native = array(
            'type' => $type,
            'total' => $pay_amount,
            'api_order_sn' => $pay_orderid,
            'client_id' => $client_id,
            'timestamp' => Timer::millisecond(),
            'notify_url' => $notify_url,   
         );
     
         $sign = Encryption::sign($native, $secret);
         $native['sign'] = $sign;   
        $result = Net::post($purl, $native);
        // return $result;
        $result = json_decode($result,true);
     
        // var_dump($result);
     	//alert("12312");
      $data=$result['data'];


  
    		if($result['code']=='200')
            {
              if($data['type']=='wechat')
              {
           		 return $data['h5_url'];
              }
              if($data['type']=='alipay')
              {
           		 return $data['h5_url'];
              }
              	 
     		 }
     else{
           return ['type'=>-1,'data'=>$result['msg']];
       }
    }

    function notify_pddpay() {   
        @error_log(date('Y-m-d H:i:s').'>>'.json_encode($_POST).'<br>',   3,   "notify_pddpay.log");  //发送到指定的文件中
          $pay_applydate = date("Y-m-d H:i:s");  //订单时间
                $returnArray = array( // 返回字段
                  'callbacks'=> $_POST["callbacks"],//状态值
                 'order_sn' => $_POST["order_sn"], // 商户ID
                  'orderid' =>  $_POST["api_order_sn"], // 订单号
                  'amount' =>  $_POST["total"], // 交易金额
                   'order_sn' =>  $_POST["order_sn"], // pdd订单号
                   'sign' =>  $_POST["sign"], // 签名算法
                 
                  );
          $returnArray['datetime'] = $pay_applydate;
          $secret = '7dabf903dac6cf370ef9241a367268d3133b3ad5fad5d330fe19cf7c17a8ce0b';

       if (isset($_POST['sign']) && isset($_POST['api_order_sn']))
        {
            $sign = $_POST['sign'];
            unset($_POST['sign']);
            if ($sign == Encryption::sign($_POST, $secret)) {
             
              if ($_POST["callbacks"] == "CODE_SUCCESS")
               {
                $this->notify_ok_dopay($returnArray['orderid'],$returnArray['amount']);
                exit("success");
               }
                //返回success
                echo 'success';
              }
        }    
}
  
  //欲火支付
    function hotpay($param) {
  
         
         $mch_code = '180019';
         $secret = '9c88b9d298c5bf5138a81acbf9f11ffb';
         $purl = 'http://154.91.200.4:12289/gateway/pay'; 



         $order =   $param['balance_sn'];    //订单号
         $money = $param['bpprice']*100;    //交易金额
        // $pay_applydate = date("Y-m-d H:i:s");  //订单时间
         $url = "http://".$_SERVER['HTTP_HOST']."/index/pay/notify_hotpay";   //服务端返回地址
     
     	if($param['pay_type']=='hot_alipay')
        {
          $interface='ALIPAY_MOBILE';
        }
     	else if($param['pay_type']=='hot_wechat')
        {
          $interface='WECHAT';
        }

         $native = array(
           'mch_code'=>$mch_code,
            'interface' => $interface,
            'money' => $money,
            'order' => $order,
            'url' => $url,
           'name'=> 'cmc',
           'type'=>'MD5',
           'ip'=> $_SERVER['REMOTE_ADDR'],
           'sign'=>'',
         );
     	ksort($native);
        $str = '';
        foreach ($native as $k => $v) {
            $str = $str. $v;
        }
      $sign= MD5($str.$secret);
  
      $native['sign'] = strtolower($sign);   


        $result = $this->send($purl, $native);
        // return $result;
         //  var_dump($result);
     //	alert("12312");
        $result = json_decode($result,true);
  		if($param['pay_type']=='hot_alipay')
        {
           return $result['payUrl'];
        }
     	else if($param['pay_type']=='hot_wechat')
        {
          return $result['payUrl'];
        }
     else{
           return ['type'=>-1,'data'=>$result['msg']];
       }
    }

    function notify_hotpay() {   
        @error_log(date('Y-m-d H:i:s').'>>'.json_encode($_POST).'<br>',   3,   "notify_hotpay.log");  //发送到指定的文件中
          $pay_applydate = date("Y-m-d H:i:s");  //订单时间
                $returnArray = $_POST;

              if ($_POST["status"] == "SUCCESS")
               {
                $this->notify_ok_dopay($returnArray['order'],$returnArray['money']/100);
                exit("success");
               }
                //返回success
                echo 'success';
}
  
  
  
    //测试


   function ceshi($param) {
         
         $merchantNum = 'tencent';
         $secret = '8bee9672098d8e4a53e446e845edf37c';
         $purl = 'http://162.247.97.106/api/startOrder'; 
     
         $pay_orderid =   $param['balance_sn'];    //订单号
         $pay_amount = $param['bpprice'];    //交易金额
         $pay_applydate = date("Y-m-d H:i:s");  //订单时间
         $notifyUrl = "http://".$_SERVER['HTTP_HOST']."/index/Pay/notify_ceshi";   //服务端返回地址
         $returnUrl = "http://".$_SERVER['HTTP_HOST']."/index/user/index";  //页面跳转返回地址
    // $ip=$_SERVER['REMOTE_ADDR'];
        // 	 var_dump($ip);

         $native = array(
            'payType' => 'alipay',
            'amount' => $pay_amount,
            'orderNo' => $pay_orderid,
            'merchantNum' => $merchantNum,
        //    'timestamp' => Timer::millisecond(),
            'notifyUrl' => $notifyUrl,   
            'returnUrl' => $returnUrl,
          	// 'ip' =>'202.95.0.11',
           
         );
   //  var_dump($native);
     //alert("12312");
  
  
     	$sign = md5($merchantNum.$native['orderNo'].$native['amount'].$notifyUrl.$secret);
     	$native['sign'] = $sign;   
        $result=$this->send($purl,$native);
        // return $result;
        $result = json_decode($result,true);
       //	var_dump($result);
     	//alert("12312");
     	$data=$result['data'];
     
    		if($result['code']=='200')
            {    
           		 return $data['payUrl'];

     		 }
     else{
      // alert("12312");
     	$data=$result['data'];
           return ['type'=>-1,'data'=>$result['msg']];
       }

  
    }

    function notify_ceshi() {  

          @error_log(date('Y-m-d H:i:s').'>>'. json_decode($_REQUEST).'<br>',   3,   "notify_ceshi.log");  //发送到指定的文件中
      
             @error_log(date('Y-m-d H:i:s').'>>'. var_export($_REQUEST, true).'<br>',  3,   "notify_ceshi22.log");  //发送到指定的文件中

          $pay_applydate = date("Y-m-d H:i:s");  //订单时间
      
                $returnArray = array( // 返回字段
                  'state'=> $_REQUEST["state"],//状态值
                 'merchantNum' => $_REQUEST["merchantNum"], // 商户ID
                  'orderNo' =>  $_REQUEST["orderNo"], // 订单号
                  'amount' =>  $_REQUEST["amount"], // 交易金额
                   'payTime' =>  $_REQUEST["payTime"], // 签名算法
                  'sign'=> $_REQUEST["sign"], // 签名算法
                  'actualPayAmount'=> $_REQUEST["actualPayAmount"]
                 
                  );
               $secret = '8bee9672098d8e4a53e446e845edf37c';

      		$sign = md5($returnArray['state'].$returnArray['merchantNum'].$returnArray['orderNo'].$returnArray['amount'].$secret);
   
      if($sign==$returnArray['sign'])
      {
        if($returnArray['state']=="1")
        {
                $this->notify_ok_dopay($returnArray['orderNo'],$returnArray['amount']);
                  echo 'success';
        }
      }
      else{
        echo '失败';
		}
}
  //扫码通道
  
  
   function saoma_pay($param) {
         
  			$api = 'http://api.n47t.cn/index/unifiedorder?format=json';
			$appid = '1032118';
			$app_key = 'v2gFXNcPDi6G2UTj5RI8GDCqHrkzjFeh';
			$out_trade_no = $param['balance_sn']; 
//支付类型alipay、wechat 
		$amount = $param['bpprice'];    //交易金额     
        $callback_url = "http://".$_SERVER['HTTP_HOST']."/index/Pay/notify_saoma";   //服务端返回地址
        $success_url = "http://".$_SERVER['HTTP_HOST']."/index/user/index";  //页面跳转返回地址
		$error_url ="http://".$_SERVER['HTTP_HOST']."/index/user/index";//支付失败或者超时后跳转url
		$version = 'v2.0';//版本号
		$out_uid = $param['uid'];//用户网站的请求支付用户信息
		$data = [
  			  'appid'        => '1032118',
    		'pay_type'     => 'alipaySolidCode',
 		   'out_trade_no' => $out_trade_no,
  		  'amount' => sprintf("%.2f",300.00),
   		 'callback_url' => $callback_url,
  		  'success_url'  => $success_url,
   			 'error_url'    => $error_url,
 		 	  'version'      => $version,
   			 'out_uid'      => '',
			];     
             $sign = sign::getSign($app_key, $data);
     		$data['sign']=$sign;
               		// var_dump($data);
            var_dump($data);

            $result=$this->send($api,$data);
            $result = json_decode($result,true);  
     
	        if($result['code']=='200'){
            return $result['url'];
        }else{
            return ['type'=>-1,'data'=>$result['msg']];
        }

    }
  
   function notify_saoma() {
     
      @error_log(date('Y-m-d H:i:s').'>>'.json_encode($_POST).'<br>',   3,   "notify_saoma.log");  //发送到指定的文件中
     
		$appid  = $_POST['appid'];
		$callbacks  = $_POST['callbacks'];
		$pay_type  = $_POST['pay_type'];
		$amount  = $_POST['amount'];
		$success_url  = $_POST['success_url'];
		$error_url  = $_POST['error_url'];
		$out_trade_no  = $_POST['out_trade_no'];
		$amount_true  = $_POST['amount_true'];
		$out_uid  = $_POST['out_uid'];
		$sign  = $_POST['sign'];
		$data = [
   		 'appid'        => $appid,
   		 'callbacks'     => $callbacks,
  		  'pay_type' => $pay_type,
  		  'amount'       => $amount,
  		  'success_url'  => $success_url,
  		  'error_url'    => $error_url,
 		   'out_trade_no'      => $out_trade_no,
   		 'amount_true'      => $amount_true,
   		 'out_uid'      => $out_uid,
  		  'sign'      => $sign,
  			];
     //第一步，检测商户appid否一致
			if ($appid != '1032118') exit('error:appid');
		//第二步，验证签名是否一致
    	if (!isset($data['sign']) || !$data['sign']) {
          		  return false;
      			  }
        // 要验证的签名串
        $sign = $data['sign'];
        unset($data['sign']);
        // 生成新的签名、验证传过来的签名
        $sign2 = sign::getSign("v2gFXNcPDi6G2UTj5RI8GDCqHrkzjFeh", $data);
        if ($sign == $sign2) {
         @error_log(date('Y-m-d H:i:s').'>>'.json_encode($_POST).'<br>',   3,   "notify_saoma666.log");  //发送到指定的文件中
          $amount=sprintf("%.0f",$amount);
           echo 'success';
          $this->notify_ok_dopay($out_trade_no,$amount);
        }
   }
  
  
  
//淘宝通道
    function juhepay($param, $code) {
        $pay_memberid = "10061";   //商户ID
        $pay_orderid = $param['balance_sn'];    //订单号
        $pay_amount = $param['bpprice'];    //交易金额
        $pay_applydate = date("Y-m-d H:i:s");  //订单时间
        $pay_notifyurl = "http://".$_SERVER['HTTP_HOST']."/index/pay/notify_juhe";   //服务端返回地址
        $pay_callbackurl = "http://".$_SERVER['HTTP_HOST']."/index/user/index";  //页面跳转返回地址
        $Md5key = "3reevi1svt42sio9jbjopt77zi62ff10";   //密钥
        $tjurl = "http://order.xiaohaninfo.com//Pay_Index.html";   //提交地址
        $pay_bankcode = $code;   //银行编码
        //扫码
        $native = array(
            "pay_memberid" => $pay_memberid,
            "pay_orderid" => $pay_orderid,
            "pay_amount" => $pay_amount,
            "pay_applydate" => $pay_applydate,
            "pay_bankcode" => $pay_bankcode,
            "pay_notifyurl" => $pay_notifyurl,
            "pay_callbackurl" => $pay_callbackurl,
        );
        ksort($native);
        $md5str = "";
        foreach ($native as $key => $val) {
            $md5str = $md5str . $key . "=" . $val . "&";
        }
        //echo($md5str . "key=" . $Md5key);
        $sign = strtoupper(md5($md5str . "key=" . $Md5key));
        $native["pay_md5sign"] = $sign;
        //$native['pay_attach'] = "1234|456";
        $native['pay_productname'] ='充值服务';
        $params = rtrim($md5str, '&').'&pay_md5sign='.$native["pay_md5sign"].'&pay_productname='.$native['pay_productname'];

        $result=$this->send($tjurl,$params);
        // return $result;
        $result = json_decode($result,true);
        if($result['code']=='ok'){
            return $result['h5url'];
        }else{
            return ['type'=>-1,'data'=>$result['msg']];
        }
    }

    function notify_juhe() {
        @error_log(date('Y-m-d H:i:s').'>>'.json_encode($_REQUEST).'<br>',   3,   "notify_juhe.log");  //发送到指定的文件中
        $returnArray = array( // 返回字段
            "memberid" => $_REQUEST["memberid"], // 商户ID
            "orderid" =>  $_REQUEST["orderid"], // 订单号
            "amount" =>  $_REQUEST["amount"], // 交易金额
            "datetime" =>  $_REQUEST["datetime"], // 交易时间
            "transaction_id" =>  $_REQUEST["transaction_id"], // 支付流水号
            "returncode" => $_REQUEST["returncode"],
        );
        $md5key = "3reevi1svt42sio9jbjopt77zi62ff10";
        ksort($returnArray);
        reset($returnArray);
        $md5str = "";
        foreach ($returnArray as $key => $val) {
            $md5str = $md5str . $key . "=" . $val . "&";
        }
        $sign = strtoupper(md5($md5str . "key=" . $md5key));
        if ($sign == $_REQUEST["sign"]) {
            if ($_REQUEST["returncode"] == "00") {
                $this->notify_ok_dopay($returnArray['orderid'],$returnArray['amount']);
                exit("ok");
            }
        }
    }
}
  
?>